package com.zmj.sy.mom.srv.aps.controller;

import com.zmj.sy.mom.srv.aps.bean.vo.base.*;
import com.zmj.sy.mom.srv.aps.bean.vo.dayworkorder.*;
import com.zmj.sy.mom.srv.aps.service.ApsDayOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequiredArgsConstructor
@Api(tags = "每日工单")
@RestController
@RequestMapping("/apsDayOrder")
public class ApsDayOrderController {

    private final ApsDayOrderService apsDayOrderService;

    private static Map<String, List<KeyValueVo>> keyValueMap = new HashMap<>();
    private static Map<String, Map<String, String>> keyValueMap1 = new HashMap<>();

    @ApiOperation("工序查询")
    @GetMapping("/phaseGet")
    public ApsDayOrderPhaseGetResVo phaseGet(ApsDayOrderPhaseGetReqVo reqVo) {
        return apsDayOrderService.phaseList(reqVo);
    }

    @ApiOperation("工序编辑")
    @PostMapping("/phaseEdit")
    public BaseResVo phaseEdit(@RequestBody ApsDayOrderPhaseEditReqVo reqVo) {
        apsDayOrderService.phaseEdit(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("生成每日审核")
    @PostMapping("/checkAdd")
    public BaseResVo checkAdd(@RequestBody ApsDayOrderCheckAddReqVo reqVo) {
        apsDayOrderService.checkAdd(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("审核列表")
    @PostMapping("/checkList")
    public BasePageResVo<ApsDayOrderCheckListResVo> checkList(@RequestBody ApsDayOrderCheckListReqVo reqVo) {
        return apsDayOrderService.checkList(reqVo);
    }

    @ApiOperation("审核详情")
    @PostMapping("/checkGet")
    public ApsDayOrderCheckGetRootResVo checkGet(@RequestBody BaseIdReqVo reqVo) {
        return apsDayOrderService.checkGet(reqVo);
    }

    @ApiOperation("审核调整")
    @PostMapping("/checkEdit")
    public BaseResVo checkEdit(@RequestBody ApsDayOrderCheckEditReqVo reqVo) {
        apsDayOrderService.checkEdit(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("审核确认")
    @PostMapping("/checkOk")
    public BaseResVo checkOk(@RequestBody BaseIdsReqVo reqVo) {
        apsDayOrderService.checkOk(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("审核智能处理")
    @PostMapping("/checkRecommend")
    public BaseResVo checkRecommend(@RequestBody BaseIdsReqVo reqVo) {
        apsDayOrderService.checkRecommend(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("动态计划-列表")
    @PostMapping("/adoList")
    public BasePageResVo<ApsDayOrderAdoListResVo> adoList(@RequestBody ApsDayOrderAdoListReqVo reqVo) {
        return apsDayOrderService.adoList(reqVo);
    }

    @ApiOperation("动态计划-详情")
    @PostMapping("/adoGet")
    public ApsDayOrderAdoGetResVo adoGet(@RequestBody ApsDayOrderAdoGetReqVo reqVo) {
        return apsDayOrderService.adoGet(reqVo);
    }

    @ApiOperation("动态计划-修改计划")
    @PostMapping("/adoEdit")
    public BaseResVo adoEdit(@RequestBody ApsDayOrderAdoEditReqVo reqVo) {
        apsDayOrderService.adoEdit(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("动态计划-修改工作组")
    @PostMapping("/adoEditGroup")
    public BaseResVo adoEditGroup(@RequestBody ApsDayOrderAdoEditGroupReqVo reqVo) {
        apsDayOrderService.adoEditGroup(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("动态计划-工序列表")
    @GetMapping("/adoPhaseList")
    public BaseListResVo<ApsDayOrderAdoPhaseListResVo> adoPhaseList(ApsDayOrderAdoPhaseListReqVo reqVo) {
        return apsDayOrderService.adoPhaseList(reqVo);
    }

    @ApiOperation("动态计划-托盘信息")
    @GetMapping("/adoPallet")
    public BaseListResVo<ApsDayOrderAdoPalletResVo> adoPallet(ApsDayOrderAdoPalletReqVo reqVo) {
        return apsDayOrderService.adoPallet(reqVo);
    }

    @ApiOperation("保存表格")
    @PostMapping("/saveTableConfig")
    public BaseResVo saveTableConfig(@RequestBody ApsDayOrderSaveTableConfigReqVo reqVo) {
        keyValueMap.put(reqVo.getSystemId() + "$$" + reqVo.getTableId() + "$$" + reqVo.getUserCode(), reqVo.getItem());
        keyValueMap1.put(reqVo.getSystemId() + "$$" + reqVo.getTableId() + "$$" + reqVo.getUserCode(), reqVo.getAttr());
        return BaseResVo.ok();
    }

    @ApiOperation("阅读表格")
    @PostMapping("/readTableConfig")
    public ApsDayOrderReadTableConfigResVo readTableConfig(@RequestBody ApsDayOrderReadTableConfigReqVo reqVo) {
        List<KeyValueVo> keyValueVos = keyValueMap.get(reqVo.getSystemId() + "$$" + reqVo.getTableId() + "$$" + reqVo.getUserCode());
        Map<String, String> stringStringMap = keyValueMap1.get(reqVo.getSystemId() + "$$" + reqVo.getTableId() + "$$" + reqVo.getUserCode());
        ApsDayOrderReadTableConfigResVo resVo = new ApsDayOrderReadTableConfigResVo();
        BeanUtils.copyProperties(reqVo, resVo);
        resVo.setItem(keyValueVos);
        resVo.setAttr(stringStringMap);
        return resVo;
    }

    @ApiOperation("删除表格")
    @PostMapping("/deleteTableConfig")
    public BaseResVo deleteTableConfig(@RequestBody ApsDayOrderReadTableConfigReqVo reqVo) {
        keyValueMap.remove(reqVo.getSystemId() + "$$" + reqVo.getTableId() + "$$" + reqVo.getUserCode());
        keyValueMap1.remove(reqVo.getSystemId() + "$$" + reqVo.getTableId() + "$$" + reqVo.getUserCode());
        return BaseResVo.ok();
    }

    @ApiOperation("动态计划-工作组查询")
    @GetMapping("/adoFindGroup")
    public BaseSelectResVo adoFindGroup(ApsDayOrderAdoFindGroupReqVo reqVo) {
        List<BaseSelectItemResVo> baseSelectItemResVos = apsDayOrderService.adoFindGroup(reqVo);
        return BaseSelectResVo.of(baseSelectItemResVos);
    }


    @ApiOperation("动态计划-调整查询")
    @GetMapping("/adoFindPlan")
    public ApsDayOrderAdoFindPlanResVo adoFindPlan(ApsDayOrderAdoFindPlanReqVo reqVo) {
        return apsDayOrderService.adoFindPlan(reqVo);
    }

    @ApiOperation("动态计划-批量修改工作组")
    @PostMapping("/adoBatchGroup")
    public BaseResVo adoBatchGroup(@RequestBody ApsDayOrderAdoBatchGroupReqVo reqVo) {
        apsDayOrderService.adoBatchGroup(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("动态计划-调整编辑")
    @PostMapping("/adoEditPlan")
    public BaseResVo adoEditPlan(@RequestBody ApsDayOrderAdoEditPlanReqVo reqVo) {
        apsDayOrderService.adoEditPlan(reqVo);
        return BaseResVo.ok();
    }


}
